home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 22 / 4 / DISK2247.ZIP / CBASE101.ZIP / BTREE101.ZIP / BTSETBUF.C < prev    next >
Text File  |  1990-06-20  |  2KB  |  86 lines

  1. /*    Copyright (c) 1989 Citadel    */
  2. /*       All Rights Reserved        */
  3.  
  4. /* #ident    "@(#)btsetbuf.c    1.4 - 90/06/20" */
  5.  
  6. #include <blkio.h>
  7. #include <errno.h>
  8.  
  9. /* local headers */
  10. #include "btree_.h"
  11.  
  12. /*man---------------------------------------------------------------------------
  13. NAME
  14.      btsetbuf - assign buffering to a btree
  15.  
  16. SYNOPSIS
  17.      #include <btree.h>
  18.  
  19.      int btsetbuf(btp, buf)
  20.      btree_t *btp;
  21.      void *buf;
  22.  
  23. DESCRIPTION
  24.      The btsetbuf function causes the storage area pointed to by buf
  25.      to be used by the btree associated with btree pointer btp instead
  26.      of an automatically allocated buffer area.  If buf is the NULL
  27.      pointer, btp will be completely unbuffered.
  28.  
  29.      The size of the storage area needed can be obtained using the
  30.      BTBUFSIZE() macro:
  31.  
  32.           char buf[BTBUFSIZE(M, KEYSIZE, BTBUFCNT)];
  33.           btsetbuf(btp, buf);
  34.  
  35.      where M is the degree of the btree, KEYSIZE is the size of the
  36.      keys int the btree, and BTBUFCNT is the default number of nodes
  37.      buffered when a btree is opened.  BTBUFCNT is defined in
  38.      <btree.h>.  If the number of nodes buffered has been changed using
  39.      btsetvbuf, then that number should be used in place of BTBUFCNT.
  40.  
  41.      btsetbuf may be called at any time after opening the btree,
  42.      before and after it is read or written; the buffers are flushed
  43.      before installing the new buffer area.
  44.  
  45.      btsetbuf will fail if one or more of the following is true:
  46.  
  47.      [EINVAL]       btp is not a valid btree pointer.
  48.      [BTENBUF]      buf is not the NULL pointer and btp
  49.                     is not buffered.
  50.      [BTENOPEN]     btp is not open.
  51.  
  52. SEE ALSO
  53.      btsetvbuf, btsync.
  54.  
  55. DIAGNOSTICS
  56.      Upon successful completion, a value of 0 is returned.  Otherwise,
  57.      a value of -1 is returned, and errno set to indicate the error.
  58.  
  59. ------------------------------------------------------------------------------*/
  60. int btsetbuf(btp, buf)
  61. btree_t *btp;
  62. void *buf;
  63. {
  64.     /* validate arguments */
  65.     if (!bt_valid(btp)) {
  66.         errno = EINVAL;
  67.         return -1;
  68.     }
  69.  
  70.     /* check if not open */
  71.     if (!(btp->flags & BTOPEN)) {
  72.         errno = BTENOPEN;
  73.         return -1;
  74.     }
  75.  
  76.     /* set buffering */
  77.     if (bsetbuf(btp->bp, buf) == -1) {
  78.         if (errno == BENBUF) errno = BTENBUF;
  79.         BTEPRINT;
  80.         return -1;
  81.     }
  82.  
  83.     errno = 0;
  84.     return 0;
  85. }
  86.